package test.com.googlecode.likesql;

import java.math.BigDecimal;
import java.math.BigInteger;

import junit.framework.TestCase;

import com.googlecode.likesql.LikeSql;
import com.googlecode.likesql.dml.DML;

public class InsertSqlTester extends TestCase {

	public void testSimpleSql(){
		String eSql="INSERT INTO users (no,id,name,gender,height) VALUES(1,15666662656565,'johny',null,195.36)";
		String eTpl="INSERT INTO users (no,id,name,gender,height) VALUES(?,?,?,?,?)";
		
		LikeSql iSql=DML.insertInto("users")
		    .value("no", 1)
		    .value("id", new BigInteger("15666662656565"))
		    .value("name","johny")
		    .value("gender",null)
		    .value("height", 195.36);
		
		assertEquals(eSql,iSql.toString());
		assertEquals(eTpl,iSql.toTemplate());
	}
	
	public void testOneColumn(){
		String eSql="INSERT INTO table (no) VALUES(1566666265656554354.49846848)";
		String eTpl="INSERT INTO table (no) VALUES(?)";
		
		LikeSql iSql=DML.insertInto("table")
		    .value("no",new BigDecimal("1566666265656554354.49846848"));
		
		assertEquals(eSql,iSql.toString());
		assertEquals(eTpl,iSql.toTemplate());
	}
	
	public void testNoColumn(){
		String eSql="INSERT INTO table VALUES()";
		String eTpl="INSERT INTO table VALUES()";
		
		LikeSql iSql=DML.insertInto("table");
		
		assertEquals(eSql,iSql.toString());
		assertEquals(eTpl,iSql.toTemplate());
	}
}
